// 异步操作
import { Operation } from "@/api";

// 加载操作列表 
let operation_list = async (context, playload) => {
    let { status, msg, data } = await Operation.list(playload);
    if (status) {
        context.commit('UPDATE_OPERATION', data);
    }
}

// 添加操作
let add_operation = async (context, playload) => {
    let { status, msg, data } = await Operation.add(playload);
    if (status) {
        // 索引从哪里来？点击删除按钮传参
        context.commit('ADD_OPERATION', { ...data, ...playload });
    }
    // 尽量在组件中实现跳转。弹窗等功能；return出去的是Promise对象
    return { status, msg }
}

// 编辑操作
let edit_operation = async (context, payload) => {
    let { status, msg } = await Operation.update(payload.operation_id, payload);
    if (status) {
        context.commit('EDIT_OPERATION', payload);
    }
    // 尽量在组件中实现跳转。弹窗等功能；return出去的是Promise对象
    return { status, msg }
}

// 删除按钮
let remove_operation = async (context, payload) => {
    let { status, msg } = await Operation.remove(payload.operation_id);
    if (status) {
        // 索引从哪里来？点击删除按钮传参
        context.commit('REMOVE_OPERATION', payload.index);
    }
    // 尽量在组件中实现跳转。弹窗等功能；return出去的是Promise对象
    return { status, msg }
}

export default {
    operation_list,
    add_operation,
    edit_operation,
    remove_operation,
}